<template>
	<view class="container" >
		<view class="status_bar">
			<view style="margin-left: 3%;" @tap="goBack()"><u-icon name="arrow-leftward" size='24' /></u-icon></view>
			<view style="font-weight: bold;margin-left: -56upx;">切换账号</view>
			<view></view>
		</view>
		<view class="wrapper">

			<view class="uni-list">
				<checkbox-group @change="checkboxChange">
					<label class="uni-list-cell" v-for="(item,index) in arr" :key="index">
						<view style="margin-left: 20upx;position: relative;">
							<view>{{item.acc}}</view>
							<view>{{item.name}}</view>
						</view>
						<view>
							<checkbox :value="item" :checked="item.checked" />
						</view>
					</label>
				</checkbox-group>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				startX: 0, // 触摸开始的X坐标
				endX: 0, // 触摸结束的X坐标
				threshold: 50, // 设置滑动多少距离后触发返回
				value1: '哈哈哈@坐席',
				textShow: true,
				groupList: [{
					groupName: 'hhh'
				}, {
					groupName: 'xxx'
				}],
				checkboxValue1: [],
				keyword: '',
				// 基本案列数据
				checkListValue: [],
				saveShow: false,
				arr: ''
			}
		},
		onLoad(props) {
			let storedArr = uni.getStorageSync('loginInfoArr') || [];

			// 去除重复项（假设以 acc 作为唯一标识）
			this.arr = this.removeDuplicates(storedArr);

			// 清空所有选中状态
			this.clearSelections();
			// console.log(props.type, "props")
			// this.type = props.type
			//	this.getDetail()
		},
		onLaunch() {
			// const currentAccount = uni.getStorageSync('currentAccount');
			// if (currentAccount) {
			// 	// 恢复登录状态
			// 	uni.setStorageSync('token', currentAccount.token);
			// 	// this.$store.commit('SET_USER_INFO', currentAccount.userInfo);
			// }
		},

		methods: {
			// 清空所有复选框的选中状态
			clearSelections() {
				this.arr = this.arr.map(item => ({
					...item,
					checked: false
				}));
			},
			// 去除重复项（根据 acc 字段去重）
			removeDuplicates(array) {
				const seen = new Set();
				return array.filter(item => {
					if (seen.has(item.acc)) {
						return false;
					}
					seen.add(item.acc);
					return true;
				});
			},
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			},
			
			
			checkboxChange(e) {
				let logoname = e.detail.value; // 获取选中的值
				this.checkListValue = logoname;

				// 跳转时携带 logoname 参数
				this.toPage('/pages/login?logoname' + JSON.stringify(logoname));

			},
			//删除
			handleDelete(id) {
				// let checkListValue1 = this.checkListValue.filter(item => item.id == id);
				// if (checkListValue1) {
				// 	checkListValue1.checked = false
				// }
				// console.log(this.checkListValue,111)
				this.checkListValue = this.checkListValue.filter(item => item.id !== id);
				// let checkListValue1 = this.checkListValue.filter(item => item.id == id);
			},
			//弹框
			recordsClose() {
				this.saveShow = false
			},
			recordsConFirm() {
				this.saveShow = false
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 100%;
		height: 100%;
	}

	.status_bar {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 50upx;
	}

	.status_bar,
	.head {
		background-color: #fff;
		height: 160upx;

		.face {
			width: 160upx;
			height: 160upx;
			border-radius: 10upx;
		}

		.info-name {
			font-size: 40upx;
			font-weight: bold;
		}

		.info-num {
			padding: 2upx 30upx;
			background: #f0f4f7;
			border-radius: 30upx;
			margin-top: 21upx;
		}

		.copybtns {
			color: #4457a4;
			margin-top: 21upx;
		}
	}

	.wrapper {
		width: 92%;
		margin-left: 4%;

		// .select-box {
		// 	margin: 10upx 1% 0 2%;
		// 	display: flex;
		// 	justify-content: space-around;
		// 	align-items: center;
		// }
		.uni-list-cell {
			justify-content: space-between;
			display: flex;
			align-items: center;
			padding: 30upx;
			margin-top: 30upx;
		}

		.name-img {
			width: 80upx;
			height: 80upx;
			border-radius: 10upx;
			background: #d54827;
			font-size: 36upx;
			text-align: center;
			line-height: 80upx;
			color: #fff;
			margin-left: 10upx;
		}

		.img-value {
			border-radius: 30upx;
			margin-left: 10upx;
			display: flex;
			margin-top: 30upx;

			.img-value1 {
				margin-left: 30upx;
				position: relative;
			}

			.delete-btn {
				position: absolute;
				top: -16%;
				left: 76%;
			}
		}
	}

	.btn-box {
		width: 92%;
		//margin-left: 4%;
		position: absolute;
		bottom: 80upx;
		background: #000;
		opacity: 0.6;
		color: #fff;
		text-align: center;
		height: 80upx;
		line-height: 80upx;
		border-radius: 20upx;
	}

	.clear-record-box {
		border-radius: 30upx;
		padding: 30upx;

		.clear-record-box-title {
			padding: 10upx 20upx;
			font-size: 40upx;
		}

		.clear-record-box-title1 {
			padding: 20upx 0 30upx 20upx;
			font-size: 30upx;
			font-weight: 300;
		}

		.clear-record-box-btn {
			display: flex;
			// padding: 30upx 0 20upx 0;
			margin-left: 150upx;
			margin-top: 30upx;
		}

		.clear-record-box-btn-left {
			padding: 10upx 30upx;
		}

		.clear-record-box-btn-right {
			background: #000;
			color: #fff;
			padding: 10upx 40upx;
			margin-left: 30upx;
		}
	}
</style>